package com.yangff.utils;

import com.yangff.entity.product.entity.Financialproduct;
import com.yangff.entity.product.entity.productentity.*;

import java.util.Random;

public class StockUtil {

    private static final double e = 2.71828;

    // 生成虚拟产品下一天的价格，采用几何布朗运动，初始价格，预期收益，波动率
    public static double generateStockNextPrices(double S0, double mu, double sigma) {

        Random random = new Random();
        // 时间步长，这里设为一天，假设一年有252天交易日
        double dt = 1.0 / 252;
        //标准差为x的正态分布
        double Wt = random.nextGaussian() * Math.sqrt(dt);
        // 计算下一天的价格
        double nextPrice = S0 * Math.exp((mu - 0.5 * sigma * sigma) * dt + sigma * Wt);
        return nextPrice;

    }


    public static Financialproduct CreateStockByType(Integer type) {
        Financialproduct stock = null;
        switch (type) {
            case 1:
                stock = new BondEntity();
                break;
            case 2:
                stock = new CurrencyEntity();
                break;
            case 3:
                stock = new FixedInvestmentEntity();
                break;
            case 4:
                stock = new FundEntity();
                break;
            case 5:
                stock = new GoldEntity();
                break;
            case 6:
                stock = new StableWealthManagementEntity();
                break;
        }
        return (stock == null ? new Financialproduct() : stock);
    }
}
